package edu.siu.math.egut.functions;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import edu.siu.math.egut.lie.AbstractEgutFunction;
import edu.siu.math.egut.lie.AbstractLiEObject;
import edu.siu.math.egut.lie.LiEText;
import edu.siu.math.egut.lie.LiEType;
import edu.siu.math.egut.lie.NonExceptionalGroupException;
import edu.siu.math.egut.util.ExceptionalGroup;
import edu.siu.math.egut.util.Polynomial;
import edu.siu.math.egut.util.PolynomialReadException;
import edu.siu.math.egut.util.OneParameterSubGroup;
import edu.siu.math.egut.util.ExceptionalGroupElement;

/**
 * Attempt to conjugate two roots from an exceptional group.
 * 
 * @author Joe Pleso
 *
 */
public class Conjugate extends AbstractEgutFunction {

	
	
	public LiEType[] argList() {
	    LiEType[] result = new LiEType[3];
	    result[0]=LiEType.VEC;
	    result[1]=LiEType.VEC;
	    result[2]=LiEType.GRP;
	    return result;
	}//Defines the arguments this function takes


	
	public void run() {

	    AbstractLiEObject[] args;
	    try {
		args = this.getData();
	    } catch (IllegalArgumentException e) {

		e.printStackTrace();
		return;
	    } catch (InstantiationException e) {

		e.printStackTrace();
		return;
	    } catch (IllegalAccessException e) {

		e.printStackTrace();
		return;
	    } catch (InvocationTargetException e) {

		e.printStackTrace();
		return;
	    } catch (NonExceptionalGroupException e) {
		return;
	    } 
	    
	    //Retrieve the arguments from the interpreter
	   
	    int[] r = (int[]) (args[0]).getJavaObject();
	    //Parse the first root
	    
	    int[] s = (int[]) (args[1]).getJavaObject();
	    //Parse the second root
	    
	    ExceptionalGroup g = (ExceptionalGroup)(args[2]).getJavaObject();
	    //Parse the group
	    


	    List<OneParameterSubGroup> list = new ArrayList<OneParameterSubGroup>();
		//List to store sunipotents
			
	    Polynomial rPolynomial = Polynomial.create("r");	//r
		
	    Polynomial sPolynomial = Polynomial.create("s");	//s
		
	    ExceptionalGroupElement u;										
		//Unipotent to do conjugation with
		
		
		
	    list.add(OneParameterSubGroup.create(r, rPolynomial));
		//Create the sunipotents
	    list.add(OneParameterSubGroup.create(s, sPolynomial));
			
			
			
	    u = new ExceptionalGroupElement (g, list);
			//u = x_r(r)x_s(s)
			
		
	    u.pushRight(0);			//do the commutation
		
	    this.setData(new LiEText(u.toString()).toString());
		//format the output as LiE text
			//and	
	    //Pass the data back to the interpreter
			
	    
	}

}
